
package com.group8.ui;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.util.Enumeration;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.group8.ge.GameObject;
import com.group8.gm.InputManager;


public class GamePanel extends JPanel{
	private Vector<GameObject> objList;
	private InputManager im;
	private JLabel score;
	
	public GamePanel(InputManager im){
		this.im = im;
		score = new JLabel(""+0);
		setPreferredSize(new Dimension(800,660));
		objList = new Vector<GameObject>();
		this.addKeyListener(im);
		setFocusable(true);
		requestFocusInWindow();
		add(score);
		revalidate();
	}
	
	public void setScore(int s){
		score.setText(""+s);
	}
	
	public void addObject(GameObject obj) {
		objList.addElement(obj);
		this.repaint();
	}
	
	public void delObj(GameObject obj) {
		objList.removeElement(obj);
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		Image bckgrnd = new ImageIcon("assets/gamePanelBackground.jpg").getImage();
		g.drawImage(bckgrnd, 0, 0, null);
		Enumeration<GameObject> venum = objList.elements();
		while(venum.hasMoreElements()){
			GameObject goj = (GameObject)venum.nextElement();
			if(goj.getY()<600)
				g.drawImage(goj.getImg(), (int)goj.getX(), (int)goj.getY(), null);
		}
		
	} 
	
	
}
